package org.yxt.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yxt.springcloud.entities.CommonResult;
import org.yxt.springcloud.service.PaymentService;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "consumer")
public class ConsumerController {

    @Resource
    private PaymentService paymentService;

    /**
     * 服务降级
     *
     * @param number
     * @return
     */
    @GetMapping(value = "fallback/{number}")
    @SentinelResource(value = "fallback", fallback = "fallBackHandler", blockHandler = "blockExceptionHandler")
    public CommonResult fallback(@PathVariable int number) {
        return paymentService.getFallBackVal(number);
    }
}
